import { defineConfig,loadEnv } from 'vite'
import type { UserConfig, ConfigEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'


// https://vite.dev/config/
export default defineConfig(({ mode }: ConfigEnv): UserConfig =>{
  const env = loadEnv(mode, process.cwd())
  return {
    plugins: [vue()],
  // 配置代理
  server: {
    open: true, // 是否启动就打开浏览器
    // 反向代理
    proxy: {
      [env.VITE_API_URL_PREFIX]: {
        target: env.VITE_API_URL,
        changeOrigin: true,
        rewrite: (path) =>
          path.replace(
           `^${env.VITE_API_URL_PREFIX}`,
            ''
          ), // 路径重写
      },
    },
  },
   resolve: {
     alias: {
       "@": path.resolve(__dirname, "./src"),
     },
        },

  }
})